package com.sixth.interceptor;

import com.sixth.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @program: SpringMvc02
 * @description:
 * @author: 高振杨
 * @create: 2021-12-06 18:34
 **/

public class Logininterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断用户是否登录了
        HttpSession session=request.getSession();
        User name = (User) session.getAttribute("user");
        if(name!=null){
            return true;
        }else {
            response.sendRedirect("../login.jsp");
            return false;
        }
    }
}
